#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ(2.61)
AC_INIT(lyricplayer, 0.2.0, [crs.chin@gmail.com])
AC_CONFIG_SRCDIR([src/main.c])
AC_CONFIG_HEADER([config.h])

AM_INIT_AUTOMAKE([1.10])

# Checks for programs.
AC_PROG_CC
AC_PROG_CC_C_O
AC_PROG_LIBTOOL
AC_PROG_SED


# Checks for libraries.
dnl FIXME: currently enca must be enabled.
AC_ARG_ENABLE(enca, [AC_HELP_STRING(--enable-enca, [enable guessing enodings using enca(default on)])], [enable_enca=yes])
if test x"$enable_enca" != xno; then
	AC_CHECK_LIB(enca, enca_analyser_alloc, ,[AC_MSG_ERROR([libary enca not found])])
	AC_CHECK_HEADER(enca.h, [AC_DEFINE(HAVE_ENCA_H, 1,[we have enca.h])], [AC_MSG_ERROR([Can't find enca.h header file])])
else
	AC_MSG_ERROR([Sorry,currently there must be library enca])
fi

# Checks for header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_CHECK_HEADERS([fcntl.h limits.h malloc.h stdlib.h string.h sys/ioctl.h unistd.h])
AC_CHECK_HEADER([ncurses.h], ,[AC_MSG_ERROR([Could not find expat.h])])
AC_CHECK_HEADER([term.h], ,[AC_MSG_ERROR([Could not find expat.h])])
AC_CHECK_HEADERS([expat.h], , [AC_MSG_ERROR([Could not find expat.h])])
AC_CHECK_HEADERS([readline/readline.h], , [AC_MSG_ERROR([Could not find readline.h])])

# Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_HEADER_STDBOOL
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_HEADER_TIME
AC_STRUCT_TM
AC_TYPE_UINT32_T

# Checks for library functions.
AC_FUNC_CLOSEDIR_VOID
AC_FUNC_FORK
AC_PROG_GCC_TRADITIONAL
AC_FUNC_MALLOC
AC_FUNC_MEMCMP
AC_FUNC_MMAP
AC_FUNC_REALLOC
AC_FUNC_SELECT_ARGTYPES
AC_TYPE_SIGNAL
AC_FUNC_VPRINTF
AC_CHECK_FUNCS([bzero dup2 ftruncate memchr memmove memset munmap realpath select strcasecmp strchr strdup strerror strrchr strstr strtol])
AC_CHECK_LIB(ncurses, setupterm, , [AC_MSG_ERROR([FAILED TO FOUND TERM LIB])])
AC_CHECK_LIB(readline, readline, , [AC_MSG_ERROR([FAILED TO FOUND library readline])])
AC_CHECK_LIB(expat, XML_ParserCreate,
			[ EXPAT_LIBS="-lexpat"  expat_found=yes ],
			[AC_MSG_ERROR([Could not find the Expat library])])


EXPAT_CFLAGS=
AC_SUBST(EXPAT_CFLAGS)
AC_SUBST(EXPAT_LIBS)

PKG_CHECK_MODULES([GLIB], glib-2.0 >= 2.16)
PKG_CHECK_MODULES([GTHREAD], gthread-2.0 >= 2.0)
PKG_CHECK_MODULES([GTK], gtk+-2.0 >= 2.12)
PKG_CHECK_MODULES([PANGOCAIRO], pangocairo)
PKG_CHECK_MODULES([XMMSC], xmms2-client >= 0.5)
PKG_CHECK_MODULES([LIBCURL], libcurl)
PKG_CHECK_MODULES([GTHREAD], gthread-2.0 >= 2.0)
PKG_CHECK_MODULES([GNOME], gnome >= 1.4)
PKG_CHECK_MODULES([LIBGLADE], libglade-2.0 >= 2.6)
PKG_CHECK_MODULES([NOTIFY], libnotify)

test "$prefix" = NONE && prefix="/usr/local/"
test "$libdir" = '${exec_prefix}/lib'  && libdir=\"$prefix/lib/\"

GLOBAL_CFLAGS="-s -DNDEBUG -DNVERBOSE"

AC_DEFINE_UNQUOTED(LIB_PREFIX, [$libdir], [plugin install prefix])
AC_DEFINE([NDEBUG], 1, [define to disable debug output])

AC_SUBST(GLOBAL_CFLAGS)

AC_SUBST(GLIB_CFLAGS)
AC_SUBST(GLIB_LIBS)

AC_SUBST(GTHREAD_CFLAGS)
AC_SUBST(GTHREAD_LIBS)

AC_SUBST(GTK_CFLAGS)
AC_SUBST(GTK_LIBS)

AC_SUBST(GNOME_CFLAGS)
AC_SUBST(GNOME_LIBS)

AC_SUBST(LIBGLADE_CFLAGS)
AC_SUBST(LIBGLADE_LIBS)

AC_SUBST(NOTIFY_CFLAGS)
AC_SUBST(NOTIFY_LIBS)

AC_SUBST(PANGOCAIRO_CFLAGS)
AC_SUBST(PANGOCAIRO_LIBS)

AC_SUBST(XMMSC_CFLAGS)
AC_SUBST(XMMSC_LIBS)

AC_SUBST(LIBCURL_CFLAGS)
AC_SUBST(LIBCURL_LIBS)

AC_CONFIG_FILES([Makefile
                 src/Makefile
                 src/client/Makefile
                 src/fetchlyric/Makefile
                 src/ui/Makefile])
AC_OUTPUT


